package m3d28;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class cEntryset {
    public static void main(String[] args) {
        //第二种方法
        Map<String,String> map1 = new HashMap<>();
        String v1 = map1.put("a","1");
        String v3 = map1.put("b","2");
        String v4 = map1.put("c","3");
        String v5 = map1.put("d","4");

        //把集合的所有Entry对象取出来，放到set集合
        Set<Map.Entry<String,String>> set = map1.entrySet();
        //遍历set集合
        Iterator<Map.Entry<String,String>> stringIterator = set.iterator();

        while(stringIterator.hasNext()){
            Map.Entry<String,String> str = stringIterator.next();
            //使用entry的方法去除键值
            String key = str.getKey();
            String value = str.getValue();
            System.out.println("key = "+key+" value = "+value);
        }
        System.out.println("==================");

        //
        for (Map.Entry<String,String> str:set
             ) {
            //使用entry的方法去除键值
            String key = str.getKey();
            String value = str.getValue();
            System.out.println("key = "+key+" value = "+value);
        }
    }

}
